package org.example.demo;

/**
 * 草莓
 */
public class Strawberry extends Fruit {

    // 是否在打折期间(实际项目为定时任务控制)
    private boolean isDiscountPeriod;
    public Strawberry() {
        super("strawberry", 13.0);
        // 默认不打折
        this.isDiscountPeriod = false;
    }

    // 设置是否在打折期间
    public void setDiscountPeriod(boolean isDiscountPeriod) {
        this.isDiscountPeriod = isDiscountPeriod;
    }

    // 重写计算价格的方法，考虑草莓打折情况
    @Override
    public double calculatePrice(double weightInKg) {
        if (isDiscountPeriod) {
            // 打折期间，草莓打 8 折
            return super.calculatePrice(weightInKg) * 0.8;
        } else {
            // 不打折期间，按原价计算
            return super.calculatePrice(weightInKg);
        }
    }
}
